<?php
/**
 * 21cnjySDK
 * @author    Simon <150986416@qq.com>
 * @filename  Autoloader.php
 * @created   2017/7/5 下午2:23
 */


define('SDK_SRC_PATH', __DIR__);
define('SDK_MODULES_PATH', __DIR__ . '/modules');

/**
 * 类自动加载器
 * Class Autoloader
 */
class Autoloader
{
    public static function getClassMap($class)
    {
        $map = array(
            'HttpException' => SDK_SRC_PATH . '/HttpException.php',
            'Client' => SDK_SRC_PATH . '/Client.php',
            'SignatureHelper' => SDK_SRC_PATH . '/SignatureHelper.php',
            'Module' => SDK_MODULES_PATH . '/Module.php',
            'Common' => SDK_MODULES_PATH . '/Common.php',
            'Document' => SDK_MODULES_PATH . '/Document.php',
            'Video' => SDK_MODULES_PATH . '/Video.php',
            'Question' => SDK_MODULES_PATH . '/Question.php',
        );

        return array_key_exists($class, $map) ? $map[$class] : '';
    }

    public static function registerClass($class)
    {
        if(false !== strpos($class,'\\') && !class_exists($class)){
            $class = basename(str_replace('\\', '/', $class));
        }

        if (is_file(self::getClassMap($class))) {
            require_once self::getClassMap($class);
        }
    }
}

spl_autoload_register(array('Autoloader', 'registerClass'));